<template>
    <div class="components_edit_modal">
        <el-dialog title="作业详情" :visible.sync="state" :show-close="true" :close-on-click-modal="false">
        <div class="components_searchs">
                <el-select v-model="selectState" clearable placeholder="请选择状态" @change="changeState" style="width:150px;">
                        <el-option v-for="state in stateList" :key="state.value" :label="state.name" :value="state.value"></el-option>
                </el-select>
        </div>

                <div class="scrollBarX">
                    <el-table :data="currentStudentScoreTable"  border stripe style="width: 100%" class="components_edit_tables">
                        <el-table-column label="序号" type="index" align="center" width="50"></el-table-column>
                        <el-table-column  prop="studentNumber"  label="学号" align="center"></el-table-column>
                        <el-table-column  prop="name"  label="学生姓名"  align="center"></el-table-column>
                        <el-table-column  prop="homeworkFile"  label="作业附件" align="center"></el-table-column>
                        <el-table-column  prop="submitTime" :formatter="formatTime"  label="提交时间" align="center"></el-table-column>
                        <el-table-column  prop="score" width="70"  label="成绩" align="center">
                        </el-table-column>
                        <el-table-column  prop="comments"  label="评语" align="center">
                        </el-table-column>
                    </el-table>
                </div>

        </el-dialog>
    </div>
</template>

<script>
    import {enums} from '@/constant'
    import { mapGetters } from 'vuex'
     import moment from 'moment'
    import PlUpload from "@/components/common/PlUpload.vue"
    export default {
        components: {
            PlUpload,
        },
        data() {
            return {
                state: false,
                selectState:null,
                studentScoreTable:[],
                currentStudentScoreTable:[],
                homeworkId:null,
                classId:null,
                stateList:[
                    {
                        value:"0",
                        name:"全部",
                    },
                    {
                        value:"1",
                        name:"已提交",
                    },
                    {
                        value:"2",
                        name:"未提交",
                    },
                ]
            }
        },
        created() {
            // 查询课程列表集合
            // this.getStudentByHomeworkAndClass();
            // 获取学期列表数据
            // this.getSemesterListByDicts();
        },
        mounted() {},
        computed:{
            ...mapGetters({
                schoolList: 'getSchoolList',
            }),
        },
        methods: {
            // 打开模态框
            showDialog(homeworkId,classId){
                this.state = true;
                this.homeworkId=homeworkId;
                this.classId=classId;
                this.getStudentByHomeworkAndClass(homeworkId,classId);
            },
            getStudentByHomeworkAndClass(homeworkId,classId){
                let self = this;
                // console.log(homeworkId,classId);
                self.axios.get(api.homeworkTeacher.queryClassStudent+"?homeworkId="+this.$route.params.id+"&classId="+classId)
                .then((response) => {
                    if(response.data.success){
                        self.studentScoreTable = JSON.parse(JSON.stringify(response.data.data));
                        self.currentStudentScoreTable = self.studentScoreTable;
                        // console.log(JSON.stringify(self.studentScoreTable));
                    }else {
                        self.$message.error(response.data.msg);
                    }
                });
            },
            changeState(){
                let currentStudentScoreTable = [];
                let studentScoreTable = this.studentScoreTable;
                let state = this.selectState;
                if(state == null || state == 0){
                    this.currentStudentScoreTable = studentScoreTable;
                    return;
                }
                for(let i=0;i<studentScoreTable.length;i++){
                    if(state == 1 && studentScoreTable[i].submitTime != null){
                        currentStudentScoreTable.push(studentScoreTable[i]);
                    }else if(state ==2 &&  studentScoreTable[i].submitTime == null){
                        currentStudentScoreTable.push(studentScoreTable[i]);
                    }
                }
                this.currentStudentScoreTable = currentStudentScoreTable;
            },
            formatTime(row, column, cellValue){
                if(typeof(cellValue)=="undefined"){
                    return "";
                }
              return  moment(cellValue).format('YYYY-MM-DD HH:mm');
            }
        },
    };
</script>
<style>
</style>